package com.zx.cloud.controller;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.common.filter.IgnoreAuth;
import com.zx.cloud.controller.client.LoanClient;
import com.zx.cloud.domain.ClientRisk;
import com.zx.cloud.domain.LoanOrder;
import com.zx.cloud.domain.RepayOrder;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.model.response.Response;
import com.zx.cloud.util.Page;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @ClassName: LoanController
 * @Description: 
 * @author: likun
 * @date: 2017年11月1日 下午6:57:00
 */
@RestController
@RequestMapping(value = ApiVersion.MANAGER_V1_PREFIX+"/loan", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class LoanController {
	@Autowired
    private LoanClient loanClient;
	
	
	@RequestLogging
	@ApiOperation(value = "借款管理-借款订单列表", notes = "借款管理-借款订单列表")
	@RequestMapping(value = "/getLoanOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getLoanOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return loanClient.getLoanOrderList(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-借款订单列表—查看详情", notes = "借款管理-借款订单列表—查看详情")
	@RequestMapping(value = "/getLoanOrderDetail", method = RequestMethod.POST)
	@ResponseBody
	public Response getLoanOrderDetail(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return loanClient.getLoanOrderDetail(loanOrder);
	}
	@RequestLogging
	@ApiOperation(value = "借款管理-创建借款订单", notes = "借款管理-创建借款订单")
	@RequestMapping(value = "/createLoanOrder", method = RequestMethod.POST)
	@ResponseBody
	public Response createLoanOrder(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody  LoanOrder loanOrder) throws NoSuchAlgorithmException, InvalidKeySpecException{
		
		return loanClient.createLoanOrder(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-借款订单列表-审核", notes = "借款管理-借款订单列表-审核")
	@RequestMapping(value = "/checkLoanOrder", method = RequestMethod.POST)
	@ResponseBody
	public Response checkLoanOrder(@RequestBody LoanOrder loanOrder){
		
		return loanClient.checkLoanOrder(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-放款订单列表", notes = "借款管理-放款订单列表")
	@RequestMapping(value = "/getLendingOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getLendingOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return  loanClient.getLendingOrderList(loanOrder);
		
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-放款订单列表-放款", notes = "借款管理-放款订单列表-放款")
	@RequestMapping(value = "/doLending", method = RequestMethod.POST)
	@ResponseBody
	public Response doLending(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return loanClient.doLending(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "我的借款订单列表", notes = "我的借款订单列表")
	@RequestMapping(value = "/getMyLoanOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getMyLoanOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return loanClient.getMyLoanOrderList(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "贷后管理-还款订单列表", notes = "贷后管理-还款订单列表")
	@RequestMapping(value = "/getRepayOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getRepayOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		
		return loanClient.getRepayOrderList(repayOrder);
	}
	@RequestLogging
	@ApiOperation(value = "贷后管理-还款订单列表-查看详情", notes = "贷后管理-还款订单列表-查看详情")
	@RequestMapping(value = "/getRepayOrderDetail", method = RequestMethod.POST)
	@ResponseBody
	public Response getRepayOrderDetail(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		
		return loanClient.getRepayOrderDetail(repayOrder);
	}
	@RequestLogging
	@ApiOperation(value = "贷后管理-还款订单列表-还款备注", notes = "贷后管理-还款订单列表-还款备注")
	@RequestMapping(value = "/repayrRemark", method = RequestMethod.POST)
	@ResponseBody
	public Response repayrRemark(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
	
		return  loanClient.repayrRemark(repayOrder);
	}
	@RequestLogging
	@ApiOperation(value = "贷后管理-还款订单列表-还款短信", notes = "贷后管理-还款订单列表-还款短信")
	@RequestMapping(value = "/repaySendSMS", method = RequestMethod.POST)
	@ResponseBody
	public Response repaySendSMS(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		
		return  loanClient.repaySendSMS(repayOrder);
	}
	@RequestLogging
	@ApiOperation(value = "贷后管理-逾期订单列表", notes = "贷后管理-逾期订单列表")
	@RequestMapping(value = "/getOverdueOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getOverdueOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		
		return loanClient.getOverdueOrderList(repayOrder);
	}
	@RequestLogging
	@ApiOperation(value = "手动生成逾期利息", notes = "手动生成逾期利息")
	@RequestMapping(value = "/handBuildOverdue", method = RequestMethod.POST)
	@ResponseBody
	public Response handBuildOverdue(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		return  loanClient.handBuildOverdue();
	}
	@RequestLogging
	@ApiOperation(value = "手动代扣", notes = "手动代扣")
	@RequestMapping(value = "/handWithhold", method = RequestMethod.POST)
	@ResponseBody
	public Response handWithhold(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		 
		return loanClient.handWithhold();
	}
	
	@RequestLogging
	@ApiOperation(value = "获取风控数据" , notes = "获取风控数据")
	@RequestMapping(value = "getClientRiskInfo", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Map<String, Object>> getClientRiskInfo(@CurrentUserId Long userId,@RequestBody ClientRisk clientRisk){
		ObjectDataResponse <Map<String, Object>> resultMap= loanClient.getClientRiskInfo(clientRisk);
		
		return resultMap;
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-借款订单列表-备注", notes = "借款管理-借款订单列表-备注")
	@RequestMapping(value = "/loanRemark", method = RequestMethod.POST)
	@ResponseBody
	public Response loanRemark(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
	
		return  loanClient.loanRemark(loanOrder);
	}
	@RequestLogging
	@ApiOperation(value = "获取支付宝页面开关", notes = "获取支付宝页面开关")
	@RequestMapping(value = "/getPaymentSwitch", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<String> getPaymentSwitch(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		return loanClient.getPaymentSwitch();
	}
	
	@RequestLogging
	@ApiOperation(value = "支付宝页面开关", notes = "支付宝页面开关")
	@RequestMapping(value = "/switchPayment", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> switchPayment(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody  int type){
		
		return loanClient.switchPayment(type);
	}
}
